@tool
class_name Guard_TargetAmount
extends Guard

enum CalcType
{
	Less,
	LessEqual,
	Equal,
	NotEqual,
	GreaterEqual,
	Greater,
}

@export var radius_cp:CompositeProperty
@export var count:int
@export var calc_type:CalcType

func is_satisfied(transition:Transition,state:State) -> bool:
	var entity:Entity = state.chart.get_expression_property("Entity")
	var detector_component:DetectComponent = entity.get_component(DetectComponent)
	if not detector_component:
		return false
	var detector_target:Detector_Target = detector_component.get_detector(GameEnum.DetectorType.Target)
	if not detector_target:
		return false
	var targets = detector_target.get_targets(entity.root.global_position,radius_cp.get_value(entity),Callable(),-1)
	return _calc_by_calc_type(targets.size(),count,calc_type)

func _calc_by_calc_type(value,target_value,calc_type:CalcType) -> bool:
	match calc_type:
		CalcType.Less:
			return value < target_value
		CalcType.LessEqual:
			return value <= target_value
		CalcType.Equal:
			return value == target_value
		CalcType.NotEqual:
			return value != target_value
		CalcType.GreaterEqual:
			return value >= target_value
		CalcType.Greater:
			return value > target_value
		_:
			return false

func _init() -> void:
	if Engine.is_editor_hint():
		resource_local_to_scene = true
